﻿using A.M.ETO;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using W.M.Materiel.Application.IServices;
using W.M.Materiel.Application.Services;
using W.M.Materiel.Domain.Entity;

namespace W.M.Materiel.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Product_configuration_attributeController : ControllerBase
    {
        private readonly IProduct_configuration_attributeServices product_Configuration_AttributeServices;

        public Product_configuration_attributeController(IProduct_configuration_attributeServices product_Configuration_AttributeServices)
        {
            this.product_Configuration_AttributeServices = product_Configuration_AttributeServices;
        }

        /// <summary>
        /// 显示产品属性信息+分页+查询
        /// </summary>
        /// <param name="pageSize">页容量</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="name">查询条件:产品属性名称</param>
        /// <returns>统一返回格式</returns>
        [HttpGet]
        public async Task<IActionResult> Getproduct_configuration_attribute(int pageSize, int pageIndex, string? name)
        {
            var list=await product_Configuration_AttributeServices.Getproduct_configuration_attribute(pageSize, pageIndex, name);
            return Ok(list);
        }


        /// <summary>
        /// 显示产品属性信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Getproduct_configuration_attributes()
        {
            var list=await product_Configuration_AttributeServices.Getproduct_configuration_attributes();
            return Ok(list);
        }

        /// <summary>
        /// 添加产品属性信息
        /// </summary>
        /// <param name="c">产品属性实体</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> GetProduct_configuration_attributeAdd(product_configuration_attribute c)
        {
            var list =await product_Configuration_AttributeServices.GetProduct_configuration_attributeAdd(c);
            return Ok(list);
        }

        /// <summary>
        /// 删除产品属性信息
        /// </summary>
        /// <param name="c">产品属性实体</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Getproduct_configuration_attributeDel(string? c)
        {
            var list =await product_Configuration_AttributeServices.Getproduct_configuration_attributeDel(c);
            return Ok(list);
        }

        /// <summary>
        /// 修改产品属性信息
        /// </summary>
        /// <param name="c">产品属性实体</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Getproduct_configuration_attributeUpdate(product_configuration_attribute c)
        {
            var list =await product_Configuration_AttributeServices.Getproduct_configuration_attributeUpdate(c);
            return Ok(list);
        }

        /// <summary>
        /// 反填产品属性信息
        /// </summary>
        /// <param name="product_attribute_id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Getbackfillproduct_configuration_attribute(string? product_attribute_id)
        {
            var list =await product_Configuration_AttributeServices.Getbackfillproduct_configuration_attribute(product_attribute_id);
            return Ok(list);
        }

        /// <summary>
        /// 导出产品属性
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ExportTiExcelproduct_configuration_attribute()
        {
            var list = product_Configuration_AttributeServices.GetShowInfor();
            var steram = new MemoryStream();
            steram.SaveAs(list);
            steram.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(steram, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = "产品属性信息.xlsx"
            };
        }
    }
}
